package com.btex.app;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.btex.app.adapter.OTCPaymentMethodsAdapter;
import com.btex.app.entity.OTCPaymentMethosdInfo;
import com.btex.app.tools.CookieTool;
import com.btex.app.tools.OTCBigImagDialog;
import com.btex.app.tools.OTCPaymentMethodsDialog;
import com.btex.app.tools.SharedPreferencesUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.util.PreferencesCookieStore;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OTCPaymentMethodsActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_menu)
    TextView mTvMenu;
    @BindView(R.id.rl_title)
    RelativeLayout mRlTitle;
    @BindView(R.id.otc_Payment_methods_recy_add)
    RecyclerView mOtcPaymentMethodsRecyAdd;
    @BindView(R.id.otc_Payment_methods_tv_add)
    TextView mOtcPaymentMethodsTvAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        setContentView(R.layout.activity_otcpayment_methods);
        ButterKnife.bind(this);
        mTvTitle.setText("收款方式");
        initOtcData();
    }

    private void initOtcData() {


        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(this);
        PreferencesCookieStore cookieStore = CookieTool.getCookieStore(MyApplication.getContextObject(), sharedPreferences);
        RequestParams params = new RequestParams();
        params.addHeader("myclient", "android");

        int num = (int) ((Math.random() * 9 + 1) * 100000);


        new HttpUtils().configCookieStore(cookieStore).send(HttpRequest.HttpMethod.GET, Config.GET_PAY_CARD, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

                String result = responseInfo.result;

                Log.i("kjqwdnkqwudhiquwh", result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if (jsonObject.getString(Config.KEY_CODE).equals("1")) {
                        Gson gson = new Gson();
                        OTCPaymentMethosdInfo otcPaymentMethosdInfo = gson.fromJson(result, OTCPaymentMethosdInfo.class);
                        List<OTCPaymentMethosdInfo.DataBean> data = otcPaymentMethosdInfo.getData();

                        OTCPaymentMethodsAdapter otcPaymentMethodsAdapter = new OTCPaymentMethodsAdapter(data, OTCPaymentMethodsActivity.this);
                        mOtcPaymentMethodsRecyAdd.setLayoutManager(new LinearLayoutManager(OTCPaymentMethodsActivity.this));
                        mOtcPaymentMethodsRecyAdd.setAdapter(otcPaymentMethodsAdapter);
                        otcPaymentMethodsAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                            @Override
                            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {

                                List<OTCPaymentMethosdInfo.DataBean> been = adapter.getData();
                                ImageView otc_Payment_methods_tv_bank_imag = (ImageView) view.findViewById(R.id.otc_Payment_methods_tv_bank_imag);
//                                Pair<View, String> pImage = Pair.create(view.findViewById(R.id.otc_Payment_methods_tv_bank_imag), "otc");

//                                ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(OTCPaymentMethodsActivity.this, otc_Payment_methods_tv_bank_imag,"otc");
//                                ActivityCompat.startActivity(OTCPaymentMethodsActivity.this, new Intent(OTCPaymentMethodsActivity.this, OTCFullImgActivity.class).putExtra("data", been.get(position).getImg()), activityOptionsCompat.toBundle());
//                                startActivity(new Intent(OTCPaymentMethodsActivity.this, OTCFullImgActivity.class).putExtra("data", been.get(position).getImg()));
//                                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                                String img = been.get(position).getImg();
                                OTCBigImagDialog otcBigImagDialog = new OTCBigImagDialog(OTCPaymentMethodsActivity.this, img);
                                otcBigImagDialog.show();

                            }
                        });

                    }
                } catch (JSONException e) {
                    e.printStackTrace();

                }

            }

            @Override
            public void onFailure(HttpException error, String msg) {

            }
        });


    }

    @Override
    public void setData() {

    }

    @Override
    public void onClick(View v) {

    }

    @OnClick({R.id.iv_back, R.id.otc_Payment_methods_tv_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.otc_Payment_methods_tv_add:
                new OTCPaymentMethodsDialog(this).show();
//                startActivity(new Intent(this, OTCAddBankActivity.class));
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initOtcData();
    }
}
